package com.example.snake;

import java.awt.*;

/**
 * @author Jason
 * @PACKAGE_NAME com.example.snake
 * @Description 坐标实体类
 * @date 2023-12-07 20:26
 */
public class Node {
    private int x;
    private int y;

    public Node() {
    }

    public Node(int x, int y) {
        this.x = x;
        this.y = y;
    }

    /**
     * 获取
     *
     * @return x
     */
    public int getX() {
        return x;
    }

    /**
     * 设置
     *
     * @param x
     */
    public void setX(int x) {
        this.x = x;
    }

    /**
     * 获取
     *
     * @return y
     */
    public int getY() {
        return y;
    }

    /**
     * 设置
     *
     * @param y
     */
    public void setY(int y) {
        this.y = y;
    }

    public String toString() {
        return "Node{x = " + x + ", y = " + y + "}";
    }

    /**
     * 绘制节点
     *
     * @param g
     */
    public void drawNode(Graphics g, int i) {
        /*区分头和身体*/
        if (0 == i) {
            g.fillOval(this.x, this.y, 20 - 1, 20 - 1);
        } else {
            g.fillRect(this.x, this.y, 20 - 1, 20 - 1);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Node node = (Node) o;
        return x == node.x && y == node.y;
    }

}
